﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace DataAccess
{
    /// <summary>
    /// 数据访问类:TB_YGSJTG
    /// </summary>
    public partial class TB_YGSJTG
    {
        public TB_YGSJTG()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(decimal NID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TB_YGSJTG");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataTable GetList(string strWhere, int startRecord, int maxRecords)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM TB_YGSJTG ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }

            return DbHelperOra.Query(strSql.ToString(), startRecord, maxRecords);
        }
        /// <summary>
        /// 获取记录数
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public static int GetCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) num ");
            strSql.Append(" FROM TB_YGSJTG ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperOra.GetSingle(strSql.ToString());
            return int.Parse(obj.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Add(Model.TB_YGSJTG model)
        {
            model.NID = CommonExecute.GetID(model.GetType().Name);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TB_YGSJTG(");
            strSql.Append("NID,CTGBH,NTGLX,CXMBH,CWXLX,CNR,NJS,FDSXPF,FSJL,FMJ,FSFBZ,FYFJE,FSHJE,CTGDW,CTGRY,CJSDW,CJSRY,DTTGRQ,DTGHRQ,CBZ)");
            strSql.Append(" values (");
            strSql.Append(":NID,:CTGBH,:NTGLX,:CXMBH,:CWXLX,:CNR,:NJS,:FDSXPF,:FSJL,:FMJ,:FSFBZ,:FYFJE,:FSHJE,:CTGDW,:CTGRY,:CJSDW,:CJSRY,:DTTGRQ,:DTGHRQ,:CBZ)");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,10),
					new OracleParameter(":CTGBH", OracleType.NVarChar),
					new OracleParameter(":NTGLX", OracleType.Number,1),
					new OracleParameter(":CXMBH", OracleType.NVarChar),
					new OracleParameter(":CWXLX", OracleType.NVarChar),
					new OracleParameter(":CNR", OracleType.NVarChar),
					new OracleParameter(":NJS", OracleType.Number,10),
					new OracleParameter(":FDSXPF", OracleType.Number,10),
					new OracleParameter(":FSJL", OracleType.Number,10),
					new OracleParameter(":FMJ", OracleType.Number,10),
					new OracleParameter(":FSFBZ", OracleType.Number,10),
					new OracleParameter(":FYFJE", OracleType.Number,10),
					new OracleParameter(":FSHJE", OracleType.Number,10),
					new OracleParameter(":CTGDW", OracleType.NVarChar),
					new OracleParameter(":CTGRY", OracleType.NVarChar),
					new OracleParameter(":CJSDW", OracleType.NVarChar),
					new OracleParameter(":CJSRY", OracleType.NVarChar),
					new OracleParameter(":DTTGRQ", OracleType.DateTime),
					new OracleParameter(":DTGHRQ", OracleType.DateTime),
					new OracleParameter(":CBZ", OracleType.NVarChar)};
            parameters[0].Value = model.NID;
            parameters[1].Value = model.CTGBH;
            parameters[2].Value = model.NTGLX;
            parameters[3].Value = model.CXMBH;
            parameters[4].Value = model.CWXLX;
            parameters[5].Value = model.CNR;
            parameters[6].Value = model.NJS;
            parameters[7].Value = model.FDSXPF;
            parameters[8].Value = model.FSJL;
            parameters[9].Value = model.FMJ;
            parameters[10].Value = model.FSFBZ;
            parameters[11].Value = model.FYFJE;
            parameters[12].Value = model.FSHJE;
            parameters[13].Value = model.CTGDW;
            parameters[14].Value = model.CTGRY;
            parameters[15].Value = model.CJSDW;
            parameters[16].Value = model.CJSRY;
            parameters[17].Value = model.DTTGRQ;
            parameters[18].Value = model.DTGHRQ;
            parameters[19].Value = model.CBZ;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool Update(Model.TB_YGSJTG model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update TB_YGSJTG set ");
            strSql.Append("CTGBH=:CTGBH,");
            strSql.Append("NTGLX=:NTGLX,");
            strSql.Append("CXMBH=:CXMBH,");
            strSql.Append("CWXLX=:CWXLX,");
            strSql.Append("CNR=:CNR,");
            strSql.Append("NJS=:NJS,");
            strSql.Append("FDSXPF=:FDSXPF,");
            strSql.Append("FSJL=:FSJL,");
            strSql.Append("FMJ=:FMJ,");
            strSql.Append("FSFBZ=:FSFBZ,");
            strSql.Append("FYFJE=:FYFJE,");
            strSql.Append("FSHJE=:FSHJE,");
            strSql.Append("CTGDW=:CTGDW,");
            strSql.Append("CTGRY=:CTGRY,");
            strSql.Append("CJSDW=:CJSDW,");
            strSql.Append("CJSRY=:CJSRY,");
            strSql.Append("DTTGRQ=:DTTGRQ,");
            strSql.Append("DTGHRQ=:DTGHRQ,");
            strSql.Append("CBZ=:CBZ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":CTGBH", OracleType.NVarChar),
					new OracleParameter(":NTGLX", OracleType.Number,1),
					new OracleParameter(":CXMBH", OracleType.NVarChar),
					new OracleParameter(":CWXLX", OracleType.NVarChar),
					new OracleParameter(":CNR", OracleType.NVarChar),
					new OracleParameter(":NJS", OracleType.Number,10),
					new OracleParameter(":FDSXPF", OracleType.Number,10),
					new OracleParameter(":FSJL", OracleType.Number,10),
					new OracleParameter(":FMJ", OracleType.Number,10),
					new OracleParameter(":FSFBZ", OracleType.Number,10),
					new OracleParameter(":FYFJE", OracleType.Number,10),
					new OracleParameter(":FSHJE", OracleType.Number,10),
					new OracleParameter(":CTGDW", OracleType.NVarChar),
					new OracleParameter(":CTGRY", OracleType.NVarChar),
					new OracleParameter(":CJSDW", OracleType.NVarChar),
					new OracleParameter(":CJSRY", OracleType.NVarChar),
					new OracleParameter(":DTTGRQ", OracleType.DateTime),
					new OracleParameter(":DTGHRQ", OracleType.DateTime),
					new OracleParameter(":CBZ", OracleType.NVarChar),
					new OracleParameter(":NID", OracleType.Number,10)};
            parameters[0].Value = model.CTGBH;
            parameters[1].Value = model.NTGLX;
            parameters[2].Value = model.CXMBH;
            parameters[3].Value = model.CWXLX;
            parameters[4].Value = model.CNR;
            parameters[5].Value = model.NJS;
            parameters[6].Value = model.FDSXPF;
            parameters[7].Value = model.FSJL;
            parameters[8].Value = model.FMJ;
            parameters[9].Value = model.FSFBZ;
            parameters[10].Value = model.FYFJE;
            parameters[11].Value = model.FSHJE;
            parameters[12].Value = model.CTGDW;
            parameters[13].Value = model.CTGRY;
            parameters[14].Value = model.CJSDW;
            parameters[15].Value = model.CJSRY;
            parameters[16].Value = model.DTTGRQ;
            parameters[17].Value = model.DTGHRQ;
            parameters[18].Value = model.CBZ;
            parameters[19].Value = model.NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static bool Delete(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_YGSJTG ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string NIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_YGSJTG ");
            strSql.Append(" where NID in (" + NIDlist + ")  ");
            int rows = DbHelperOra.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Model.TB_YGSJTG GetModel(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CTGBH,NTGLX,CXMBH,CWXLX,CNR,NJS,FDSXPF,FSJL,FMJ,FSFBZ,FYFJE,FSHJE,CTGDW,CTGRY,CJSDW,CJSRY,DTTGRQ,DTGHRQ,CBZ from TB_YGSJTG ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            Model.TB_YGSJTG model = new Model.TB_YGSJTG();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CTGBH"] != null && ds.Tables[0].Rows[0]["CTGBH"].ToString() != "")
                {
                    model.CTGBH = ds.Tables[0].Rows[0]["CTGBH"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NTGLX"] != null && ds.Tables[0].Rows[0]["NTGLX"].ToString() != "")
                {
                    model.NTGLX = decimal.Parse(ds.Tables[0].Rows[0]["NTGLX"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CXMBH"] != null && ds.Tables[0].Rows[0]["CXMBH"].ToString() != "")
                {
                    model.CXMBH = ds.Tables[0].Rows[0]["CXMBH"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CWXLX"] != null && ds.Tables[0].Rows[0]["CWXLX"].ToString() != "")
                {
                    model.CWXLX = ds.Tables[0].Rows[0]["CWXLX"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CNR"] != null && ds.Tables[0].Rows[0]["CNR"].ToString() != "")
                {
                    model.CNR = ds.Tables[0].Rows[0]["CNR"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NJS"] != null && ds.Tables[0].Rows[0]["NJS"].ToString() != "")
                {
                    model.NJS = decimal.Parse(ds.Tables[0].Rows[0]["NJS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FDSXPF"] != null && ds.Tables[0].Rows[0]["FDSXPF"].ToString() != "")
                {
                    model.FDSXPF = decimal.Parse(ds.Tables[0].Rows[0]["FDSXPF"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FSJL"] != null && ds.Tables[0].Rows[0]["FSJL"].ToString() != "")
                {
                    model.FSJL = decimal.Parse(ds.Tables[0].Rows[0]["FSJL"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FMJ"] != null && ds.Tables[0].Rows[0]["FMJ"].ToString() != "")
                {
                    model.FMJ = decimal.Parse(ds.Tables[0].Rows[0]["FMJ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FSFBZ"] != null && ds.Tables[0].Rows[0]["FSFBZ"].ToString() != "")
                {
                    model.FSFBZ = decimal.Parse(ds.Tables[0].Rows[0]["FSFBZ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FYFJE"] != null && ds.Tables[0].Rows[0]["FYFJE"].ToString() != "")
                {
                    model.FYFJE = decimal.Parse(ds.Tables[0].Rows[0]["FYFJE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FSHJE"] != null && ds.Tables[0].Rows[0]["FSHJE"].ToString() != "")
                {
                    model.FSHJE = decimal.Parse(ds.Tables[0].Rows[0]["FSHJE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CTGDW"] != null && ds.Tables[0].Rows[0]["CTGDW"].ToString() != "")
                {
                    model.CTGDW = ds.Tables[0].Rows[0]["CTGDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CTGRY"] != null && ds.Tables[0].Rows[0]["CTGRY"].ToString() != "")
                {
                    model.CTGRY = ds.Tables[0].Rows[0]["CTGRY"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CJSDW"] != null && ds.Tables[0].Rows[0]["CJSDW"].ToString() != "")
                {
                    model.CJSDW = ds.Tables[0].Rows[0]["CJSDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CJSRY"] != null && ds.Tables[0].Rows[0]["CJSRY"].ToString() != "")
                {
                    model.CJSRY = ds.Tables[0].Rows[0]["CJSRY"].ToString();
                }
                if (ds.Tables[0].Rows[0]["DTTGRQ"] != null && ds.Tables[0].Rows[0]["DTTGRQ"].ToString() != "")
                {
                    model.DTTGRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTTGRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTGHRQ"] != null && ds.Tables[0].Rows[0]["DTGHRQ"].ToString() != "")
                {
                    model.DTGHRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTGHRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CBZ"] != null && ds.Tables[0].Rows[0]["CBZ"].ToString() != "")
                {
                    model.CBZ = ds.Tables[0].Rows[0]["CBZ"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CTGBH,NTGLX,CXMBH,CWXLX,CNR,NJS,FDSXPF,FSJL,FMJ,FSFBZ,FYFJE,FSHJE,CTGDW,CTGRY,CJSDW,CJSRY,DTTGRQ,DTGHRQ,CBZ ");
            strSql.Append(" FROM TB_YGSJTG ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "TB_YGSJTG";
            parameters[1].Value = "NID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

